/*
 * MapObstacle.cpp
 *
 *	Version 1.0
 *  Created on: Oct 5, 2010
 *      Author: Mark Zmek
 *
 *  Copyright 2010 Michigan Technological University. All rights reserved.
 */
#include "sprite.h"
#include "MapObstacle.h"
#include <iostream>

#define DELAY_MULT 20

MapObstacle::MapObstacle(Renderer * render, SDL_Rect pos , SDL_Surface * img , GLuint id){
	rnd=render;
	image=img;
	position=pos;
	texId=id;
	angle=0;
	drawPos=new SDL_Rect();
	drawPos->x=pos.x;
	drawPos->y=pos.y;
	drawPos->w=pos.w;
	drawPos->h=pos.h;
	
	hitbox = new Hitbox(57, 68, 37, 45);
	radius = 90;
}

MapObstacle::~MapObstacle(){
	delete hitbox;
	delete drawPos;
	//the image will be freed by the map
}

//moves the obstacle
void MapObstacle::move(Uint32 ticks){
	position.x += (int)((ticks/1000.0f)*DELAY_MULT*xVelocity);
	position.y += (int)((ticks/1000.0f)*DELAY_MULT*yVelocity);
}

void MapObstacle::show(){
	rnd->drawSurface(&position,angle,texId);
}

//draws the obstacle on the screen with the upper left corner of the screen at map coordinates (x,y)
void MapObstacle::show(int x, int y){
	drawPos->x=position.x-x;
	drawPos->y=position.y-y;
	rnd->drawSurface(drawPos,angle,texId);
}

//sets the x and y velocities of the obstacle
void MapObstacle::setVelocities(int xVel, int yVel){
	xVelocity=xVel;
	yVelocity=yVel;
}
